package com.yiwei.zhh.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.zhh.R;
import com.yiwei.zhh.adapter.base.ItemAdapter;
import com.yiwei.zhh.model.ShareRecordModel;
import com.yiwei.zhh.util.DateTime;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/17 0017.
 */

public class InviteRecordAdapter extends ItemAdapter<ShareRecordModel.DataBean.ListsBean, InviteRecordAdapter.InviteRecordViewHolder> {


    public InviteRecordAdapter(Context context) {
        super(context);
    }

    @Override
    public InviteRecordViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new InviteRecordViewHolder(inflate(R.layout.item_invite_record, parent));
    }

    @Override
    public void onBindViewHolder(InviteRecordViewHolder holder, int position) {
        ShareRecordModel.DataBean.ListsBean item = getItem(position);
        holder.item = item;
        holder.txtLeft.setText(item.bonus_type_name + "\n" + item.money + "元");
        if (item.receive_status == 0) {
            holder.layoutTotal.setBackgroundResource(R.mipmap.img_invite_item_bg);
        } else if (item.receive_status == 1) {
            holder.layoutTotal.setBackgroundResource(R.mipmap.img_invite_item_xianjin);
            holder.txtRight.setText("立即领取");
        }
        holder.txtCenter.setText("有效期至" + DateTime.toDayUTF8Time(item.use_end_time * 1000));
    }

    public interface OnShareClickListener {
        void onClick(String bonus_id);
    }

    private OnShareClickListener shareClickListener;

    public void setShareClickListener(OnShareClickListener shareClickListener) {
        this.shareClickListener = shareClickListener;
    }

    class InviteRecordViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        @BindView(R.id.txt_left)
        TextView txtLeft;
        @BindView(R.id.txt_right)
        TextView txtRight;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;
        @BindView(R.id.txt_center)
        TextView txtCenter;
        ShareRecordModel.DataBean.ListsBean item;

        public void bindData() {

        }

        private InviteRecordViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (shareClickListener != null) {
                if (item.receive_status == 0 || item.receive_status == 2) {
                    return;
                }
                shareClickListener.onClick(item.id);
            }
        }
    }
}
